package com.biz.jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import com.util.ConnDatabase;
import com.util.DbUtil;


/**
 * @author liuchao
 * @version $Id: CatsDao.java,v 0.1 2012-9-15 ����12:00:14 liuchao Exp $
 */
public class CatsDao {
    
    public static final String SQL_SELECT = String.format(
        "insert into %s (%s,%s,%s) values (?,?,?)"  ,
        "props",
        "pid",
        "pname",
        "cid"
          );
    
    ConnDatabase connDatabase = new ConnDatabase();
    Statement stmt = null;
    ResultSet rs = null;
    PreparedStatement pstmt = null;
    String sql = null;
    
    
    public List<Cats> getCats() throws SQLException{
        Connection conn = DbUtil.getConnection();
        try{
            sql="select * from cat ";
            stmt = conn.createStatement();
            rs = stmt.executeQuery(sql);
            List<Cats> cats = new ArrayList<Cats>();
            while(rs.next()){
                Cats cat = new Cats();
                Long cid = rs.getLong("cat_id");
                cat.setCid(cid);
                cats.add(cat);
            }
            return cats;
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
        finally{
            connDatabase.CloseConnection(conn, stmt, rs);
        }
        return null;
    }
    
    public class Cats {
        Long    id;
        Long    cid;
        String  cName;
        Long    pcid;
        String  pcName;
        public Long getId() {
            return this.id;
        }
        public void setId(Long id) {
            this.id = id;
        }
        public Long getCid() {
            return this.cid;
        }
        public void setCid(Long cid) {
            this.cid = cid;
        }
        public String getcName() {
            return this.cName;
        }
        public void setcName(String cName) {
            this.cName = cName;
        }
        public Long getPcid() {
            return this.pcid;
        }
        public void setPcid(Long pcid) {
            this.pcid = pcid;
        }
        public String getPcName() {
            return this.pcName;
        }
        public void setPcName(String pcName) {
            this.pcName = pcName;
        }
    }

}
